package com.hadwinling.article.service.impl;

import com.hadwinling.article.entity.Article;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.hadwinling.article.mapper.ArticleMapper;
import com.hadwinling.article.service.ArticleService;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @Package com.hadwinling.article.service.impl
* @author HadwinLing
* @date 2020/10/8 17:05
* @version V1.0
*/
@Service
@Transactional
public class ArticleServiceImpl implements ArticleService{

    @Resource
    private ArticleMapper articleMapper;

    @Override
    public List<Article> selectAllArticle() {
        return articleMapper.selectAllArticle();
    }

    @Override
    public Integer selectViewcountById(Integer id) {
        return articleMapper.selectViewcountById(id);
    }

    @Override
    public int updateViewcountById(Integer updatedViewcount, Integer id) {
        return articleMapper.updateViewcountById(1,id);
    }

    @Override
    public int insertSelective(Article article) {
        return articleMapper.insertSelective(article);
    }

    @Override
    public int deleteById(Integer id) {
        return articleMapper.deleteById(id);
    }


//注解开发
   /* @Override
    @Cacheable(cacheNames = "articles")
    public List<Article> selectAllArticle() {
        return articleMapper.selectAllArticle();
    }

    @Override
    @Cacheable(cacheNames = "articleview", key = "#id")
    public Integer selectViewcountById(Integer id) {
        return articleMapper.selectViewcountById(id);
    }

    @Override
    @CacheEvict(cacheNames = "delete" ,allEntries=true)
    public int deleteById(Integer id) {
        return articleMapper.deleteById(id);
    }

    @Override
    @Cacheable(cacheNames = "article")
    public int insertSelective(Article article) {
        return articleMapper.insertSelective(article);
    }

    @Override
    @CachePut(cacheNames = "update",key = "#id")
    public int updateViewcountById(Integer updatedViewcount, Integer id) {
        return articleMapper.updateViewcountById(updatedViewcount, id);
    }*/



}
